package com.itheima02.service;

import com.itheima02.bean.Student;
import com.itheima02.mapper.StudentMapper;
import com.itheima02.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    SqlSession sqlSession = MyBatisUtils.getSqlSession();
    StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);

    @Override
    public List<Student> findByIds(List<Integer> ids) {
        List<Student> list = mapper.findByIds(ids);
        sqlSession.close();
        return list;
    }

    @Override
    public List<Student> findCondition(Student stu) {
        List<Student> list = mapper.findCondition(stu);
        sqlSession.close();
        return list;
    }

    @Override
    public List<Student> findByNameOrAge(String name, Integer age) {
        List<Student> list = mapper.findByNameOrAge(name, age);
        sqlSession.close();
        return list;
    }

    @Override
    public List<Student> selectAll() {
        List<Student> list = mapper.selectAll();
        sqlSession.close();
        return list;
    }

    @Override
    public Student selectById(Integer id) {
        Student student = mapper.selectById(id);
        sqlSession.close();
        return student;
    }

    @Override
    public int insert(Student stu) {
        int res = mapper.insert(stu);
        sqlSession.close();
        return res;
    }

    @Override
    public int delete(Integer id) {
        int res = mapper.delete(id);
        sqlSession.close();
        return res;
    }

    @Override
    public int update(Student stu) {
        int res = mapper.update(stu);
        sqlSession.close();
        return res;
    }
}
